﻿using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media;
using MusicFluent.Controls;
using MusicFluent.Models;
using MusicFluent.Views;
using NetEasyMusic.Lib.Models;

namespace MusicFluent.Pages;

public abstract class PageViewBase : UserControl
{
    public void PlaylistTapped(object? sender, TappedEventArgs e)
    {
        if (sender is not Control control) return;
        if (control.DataContext is not PlaylistModel model) return;
        var main = ViewOpera.GetView<MainWindow>(this);
        if (main == null) return;
        main.TaskShow();
        var view = new MusicViews.PlaylistView(model, main.Cookie);
        main.Navigate(view);
        main.TaskShow();
    }
    
    public async void DescTapped(object? sender, TappedEventArgs e)
    {
        if (sender is not TextBlock block) return;

        await MusicDialog.ShowMusicDialog(new TextBlock()
        {
            Text = block.Text, Width = 450,
            TextWrapping = TextWrapping.WrapWithOverflow
        }, (Visual)VisualRoot!);
    }
}